import 'package:flutter/material.dart';

class CheckBoxPage extends StatefulWidget {
  @override
  _CheckBoxPageState createState() => _CheckBoxPageState();
}

class _CheckBoxPageState extends State<CheckBoxPage> {
  var _flag = true;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('checkbox'),
      ),
      body: Column(
        children: <Widget>[
          Row(
            children: <Widget>[
              Checkbox(
                value: _flag,
                activeColor: Colors.blue,
                onChanged: (v){
                  setState(() {
                    this._flag = v;
                  });
                },),
            ],
          ),
          Row(
            children: <Widget>[
              Text('${this._flag?'选中':'未选中'}'),
            ],
          ),
          CheckboxListTile(
            value: this._flag,
            title: Text('标题'),
            subtitle: Text('二级标题'),
            onChanged: (v) {
              setState(() {
                this._flag = v;
              });
            },
          ),
          Divider(),
          CheckboxListTile(
            value: this._flag,
            title: Text('带图标'),
            subtitle: Text('带图标'),
            secondary: Icon(Icons.home),
            onChanged: (v) {
              setState(() {
                this._flag = v;
              });
            },
          ),
        ],
      )
    );
  }
}
